/**
 * Created by BigBi on 2017/3/29.
 */
var events = require('events');
var eventEmitter = new events.EventEmitter();

var handler = function () {
    console.log('copy that!');
}

//定义 监听事件
eventEmitter.on('answer',handler);

eventEmitter.on('ask',function(){
    eventEmitter.emit('answer');
})

//下发 事件
setTimeout(function(){
    eventEmitter.emit('ask');
},1000)


//带参数的 事件
eventEmitter.on('attack', function (arg1,arg2) {
    console.log('do attack:',arg1,arg2);
})
eventEmitter.emit('attack','伤敌八百','自损一千')